package com.huluobo.a2207parkdemo.x5

import android.content.Context
import android.util.AttributeSet
import com.tencent.smtt.sdk.WebView
import com.tencent.smtt.sdk.WebViewClient

/**
 *  Created by LC on 2024/11/16.
 */
class X5WebView(context: Context, attributeSet: AttributeSet) : WebView(context, attributeSet) {
    private val webViewClient = object : WebViewClient() {
        //防止加载网页时调起系统浏览器
        override fun shouldOverrideUrlLoading(view: WebView?, url: String?): Boolean {
            if (view != null && url != null) {
                view.loadUrl(url)
            }
            return true
        }
    }

    init {
        //设置网页客户端(防止调起系统浏览器)
        setWebViewClient(webViewClient)
        //让WebView可以加载JS
        initWebViewSetting()
        //设置WebView可点击
        view.isClickable = true
    }

    private fun initWebViewSetting() {
        val webViewSetting = settings
        webViewSetting.javaScriptEnabled = true
    }
}